Difference between jquery.clone() and simple concatenation of string [closed]

Posted by Francis Cebu on Programmers See other posts from Programmers or by Francis Cebu
Published on 2012-10-23T02:00:44Z Indexed on 2012/10/23 5:25 UTC
Read the original article Hit count: 317

Filed under:
|
|
|

Which of the following code samples is faster in generating HTML code using jQuery?

Sample 1:

var div = $("<div>");
$.each(data,function(count,item){
    var Elem = div.clone().addClass("message").html(item.Firstname);
    $(".container").append(Elem);
});

Sample 2:

$.each(data,function(count,item){
    var Elem = "<div class = 'Elem'>" + item.Firstname + "</div>";
    $(".container").append(Elem);
});

© Programmers or respective owner

Related posts about JavaScript

Related posts about html